import { Component, OnInit } from '@angular/core';
import {AppState} from "../store";
import {select, Store} from "@ngrx/store";
import {Observable} from "rxjs";
import {decrement, increment, increment_async } from "../store/actions/counter.actions"
import {selectCount} from "../store/selectors/counter.selectors";
import {selectmemo} from "../store/selectors/memo.selectors";
import {add} from "../store/actions/memo.actions";

@Component({
  selector: 'app-ng-rx',
  templateUrl: './ng-rx.component.html',
  styles: [
  ]
})
export class NgRxComponent implements OnInit {
  count: Observable<number>
  text : string = '';
  list: Observable<unknown>;
  constructor(private store: Store<AppState>) {
    this.count = this.store.pipe(select(selectCount))
    this.list = this.store.pipe(select(selectmemo))
  }

  ngOnInit(): void {
  }

  increment() {
    // this.store.dispatch(increment())
    this.store.dispatch(increment({ count: 5 }))
  }
  decrement() {
    this.store.dispatch(decrement())
  }
  increment_async() {
    this.store.dispatch(increment_async())
  }

  onKeyUp($event: any) {
    this.store.dispatch(add())
  }
}
